﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using XRPGLibrary.SpriteClasses;

namespace myRPG.GameScreens.Combat
{
    public enum FightState {Moving, Attack, Die }
    public class Fighter:AnimationSprite
    {
        #region Character States
        protected int health;
        protected int armer;
        protected int attackPower;
        #endregion

        protected int counter = 0;
        protected AnimationKey moveDirection = AnimationKey.Right;
        protected AnimationKey attackDirection = AnimationKey.AttackRight;
        protected FightState state = FightState.Moving;

        public FightState State
        {
            get
            {
                return state;
            }
            set
            {
                state = value;
            }
        }

        public bool IsDead
        {
            get
            {
                return (state == FightState.Die);
            }
        }

        public Fighter(Texture2D img, Dictionary<AnimationKey,Animation> animations)
            : base(img, animations)
        {
            currentAnimation = AnimationKey.Right;
            isAnimating = true;
        }

        public void Attack()
        {
            if (state == FightState.Moving)
            {
                counter = 96;
                state = FightState.Attack;
            }
        }

        public void CheckCollision(Rectangle weapon)
        {
            Rectangle rec = new Rectangle((int)position.X, (int)position.Y, Width, Height);
            if (weapon.Intersects(rec))
            {
                state = FightState.Die;
            }

        }

        public void Move(float x, float y)
        {
            velocity.X = x;
            velocity.Y = y;
        }

        public override void  Update(GameTime gameTime)
        {
            switch(state)
            {
                case FightState.Moving:
                    CurrentAnimation = moveDirection;
                    break;
                case FightState.Attack:
                    counter--;
                    CurrentAnimation = attackDirection;
                    if (counter <= 0)
                        state = FightState.Moving;
                    break;
                case FightState.Die:
                    break;
            }
            
 	        base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, XRPGLibrary.TileEngine.Camera camera)
        {
            if (!IsDead)
                base.Draw(gameTime, spriteBatch, camera);
        }
    }
}
